package com.sinven.serivce;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sinven.common.Pager;
import com.sinven.mapper.LeaveMapper;
import com.sinven.pojo.Leave;

@Service
public class LeaveSerivceImpl implements LeaveSerivce{
 
	@Autowired
	private LeaveMapper leaveMapper;

	@Override
	public long countLeave() {	
		//返回数据库总条数 
		return leaveMapper.countLeave();
	}

	@Override
	public Pager<List<Leave>> queryAll(long startIndex, long pageSize) {
		long totalRecords=leaveMapper.countLeave();
		 if (totalRecords == 0) {
				return null;
			}
		 Pager<List<Leave>> pager = 
				 new Pager<>(totalRecords, startIndex, (int)pageSize);
		 List<Leave> leave = leaveMapper.queryAll(pager.getStartIndex(), pager.getPageSize());
		 pager.setData(leave);
		return pager;
	}

	@Override
	public Boolean addLeave(Leave leave) {
		//定义row   如果添加成功
		int row = leaveMapper.addLeave(leave);
		if (row>0) {
			return true;
			//返回true
		}
		return false;
		//否则返回false
	}
}
